package org.cskt.sl.util;

public class Pager implements java.io.Serializable {

	private static final long serialVersionUID = 1091439352387636775L;

	private Integer currentPage = 1; // 当前页数

	private Integer totalCount; // 总页数

	private Integer totalPageCount; // 总记录数(使用countXxx方法得到的值赋给它)

	private Integer pageSize = 3; // 单页显示条数

	public Pager(){}
	
	/**
	 * 总是先给pageSize赋值,然后给totalPageCount总记录数赋值,再修改 currentPage
	 * @param pageSize 
	 * @param totalPageCount
	 * @param currentPage
	 */
	public Pager(int pageSize,int totalPageCount,int currentPage){
		this.pageSize=pageSize;
		setTotalPageCount(totalPageCount);
		setCurrentPage(currentPage);
	}
	
	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		if (currentPage > totalCount) {
			currentPage = totalCount;
		}
		if (currentPage < 1) {
			currentPage = 1;
		}
		this.currentPage = currentPage;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
	}

	public Integer getTotalPageCount() {
		return totalPageCount;
	}

	public void setTotalPageCount(Integer totalPageCount) {
		this.totalPageCount = totalPageCount;
		this.totalCount = this.totalPageCount % pageSize == 0 ? //
				this.totalPageCount / pageSize : //
				this.totalPageCount / pageSize + 1;
		//总是先给pageSize赋值,然后给totalPageCount总记录数赋值,再修改 currentPage
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
}
